package com.lovingtour.manager.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lovingtour.manager.R;
import com.lovingtour.manager.entity.OldCareOrderEntity;

public class OldCareOrderListItemAdapter extends BaseAdapter {

	private ArrayList<OldCareOrderEntity> dataSources;
	private LayoutInflater inflater;

	public OldCareOrderListItemAdapter(Context context,
			ArrayList<OldCareOrderEntity> dataSources) {
		setDataSources(dataSources);
		inflater = LayoutInflater.from(context);
	}

	public void setDataSources(ArrayList<OldCareOrderEntity> dataSources) {
		if (dataSources != null) {
			this.dataSources = dataSources;
		} else {
			this.dataSources = new ArrayList<OldCareOrderEntity>();
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return dataSources.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return dataSources.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.orderlist_item, parent,false);
			holder = new ViewHolder();
			holder.tv_col1 = (TextView) convertView.findViewById(R.id.item1);
			holder.tv_col2 = (TextView) convertView.findViewById(R.id.item2);
			holder.tv_col3 = (TextView) convertView.findViewById(R.id.item3);
		    convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		OldCareOrderEntity entity = dataSources.get(position);
		holder.tv_col1.setText(entity.getName());
		holder.tv_col2.setText(entity.getNum());
		holder.tv_col3.setText(entity.getTotalmoney_or_org());
		return convertView;
	}
	private class ViewHolder{
		private TextView tv_col1;
		private TextView tv_col2;
		private TextView tv_col3;
	}

}
